package com.token.sysflow.service;

import com.alibaba.fastjson.JSONArray;
import com.token.base.Pl;
import com.token.sql.IntegrateSql;

/**
 * @author chenjianxiong 2020/5/7
 */
public class DeptSelectTree extends SelectTree {

    /**
     * @param iSql
     */
    public DeptSelectTree(IntegrateSql iSql) {
        super(iSql);
    }

    /**
     * @return
     * @throws Exception
     */
    public JSONArray readData() throws Exception {
        prepareSql.setPrepare("select UnitID as id,case when ParentID='root' then '' else ParentID end as pid,UnitName as name from F_Sys_Unit where SysId=?");
        prepareSql.setPstValue(1, Pl.getSysId());
        doWhileToJson(prepareSql.executeQuery(), false,false);

        prepareSql.setPrepare("select DepartmentNumber as id,case when ParentDeptID='root' then ComID else ParentDeptID end as pid,DepartmentName as name from F_Sys_Department where SysId=?");
        prepareSql.setPstValue(1, Pl.getSysId());
        doWhileToJson(prepareSql.executeQuery(), this.getCheckable(),true);

        return array;
    }
}
